fix: support fs.watch on non-recursive platforms and make better-sqlite3 optional#21
fix: support fs.watch on non-recursive platforms and make better-sqlite3 optional#21httpsVishu wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
3 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/providers/shared/watch.ts">
<violation number="1" location="src/providers/shared/watch.ts:36">
P2: Platform allowlist incorrectly disables recursive fs.watch on Linux runtimes that support it, causing potential missed nested file change events.</violation>
</file>
<file name="src/providers/opencode/provider.ts">
<violation number="1" location="src/providers/opencode/provider.ts:30">
P2: Using top-level CommonJS `require("better-sqlite3")` in an ESM-distributed package can fail in ESM runtime paths and silently disable the OpenCode provider.</violation>
</file>
<file name="tests/opencode-fixtures.ts">
<violation number="1" location="tests/opencode-fixtures.ts:6">
P2: Catching all errors when requiring `better-sqlite3` can hide real runtime/dependency failures by silently skipping sqlite tests.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
vtemian
left a comment
There was a problem hiding this comment.
Thanks for the contribution! The problems you're solving (Linux fs.watch compat, optional native deps) are real and valuable. However, the implementation needs some changes to align with the project's coding standards:
-
No
anytypes — the project strictly forbidsany(see CLAUDE.md). All theanyusages (betterSqlite3: any,_testDb?: any,db: any, etc.) need to be replaced with proper typing usingunknown+ type guards or conditional dynamic imports. -
require()in ESM —package.jsonhas"type": "module", so barerequire()won't work correctly. Useawait import("better-sqlite3")with a lazy init pattern instead. -
Silent
catch {}— the empty catch hides real errors (native build failures, ABI mismatch). Please narrow toMODULE_NOT_FOUNDand re-throw other errors. -
Missing warning for non-recursive watch — on Linux, only top-level directory changes are detected without recursive watch. The code should emit a warning when
recursive: trueis unavailable so users know about the limitation. -
Test describe string —
opencode-provider.test.tschanges the describe label to"..."(literal dots), losing the actual suite name.
Would love to see a v2 addressing these. The direction is right, just needs implementation cleanup.
93e3ca3 to
d156c87
Compare

What
Fixes cross-platform issues with
fs.watchand improves handling of optional dependencies.Why
While setting up and running the project on a Linux/WSL environment,
fs.watchwith recursive support caused runtime errors, andbetter-sqlite3being treated as required also broke tests when not installed. This PR ensures smoother setup and execution across platforms.Results
fs.watchoptionsChecklist
npm run checkpassesSummary by cubic
Fix cross-platform file watching by probing for recursive support and falling back when unsupported. Make
better-sqlite3optional with safe loading and graceful provider disablement; SQLite-only tests auto-skip when the module or bindings are missing.fs.watchwith{ recursive: true }; on failure, warn and reopen without recursion so top-level changes still trigger.better-sqlite3viarequireand handleMODULE_NOT_FOUND/ERR_DLOPEN_FAILED/bindings-missing; disable the OpenCode provider instead of crashing, and propagate non-availability errors only when unrelated.better-sqlite3’sDatabaseand allow_testDbinjection; addhasSqlitein fixtures to gate database/provider tests.Written for commit d156c87. Summary will update on new commits.